import apiClient from './client'
import type { 
  Address, 
  AddressCreateRequest, 
  AddressUpdateRequest, 
  AddressSetDefaultRequest
} from '@/types'

export const addressService = {
  // ===== 用户地址管理模块 (/api/v1/address) =====
  
  // 获取用户地址列表 (从JWT token自动获取userId)
  getAddressList: () =>
    apiClient.get<Address[]>('/api/v1/address/list'),

  // 添加用户地址
  addAddress: (addressData: AddressCreateRequest) =>
    apiClient.post<Address>('/api/v1/address/add', addressData),

  // 更新用户地址
  updateAddress: (addressData: AddressUpdateRequest) =>
    apiClient.post<Address>('/api/v1/address/update', addressData),

  // 删除用户地址
  deleteAddress: (params: { addressId: number }) =>
    apiClient.post('/api/v1/address/delete', undefined, { params }),

  // 设置默认地址
  setDefaultAddress: (params: { addressId: number }) =>
    apiClient.post('/api/v1/address/set-default', undefined, { params })
}

export default addressService
